package com.gaoyubo.service;

import com.gaoyubo.dao.GoodsDao;
import com.gaoyubo.entity.Goods;
import com.gaoyubo.vo.GoodsVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService{
    @Autowired
    private GoodsDao goodsDao;

    @Override
    public PageInfo<Goods> getList(Integer pageNum, Integer pageSize, GoodsVo goodsVo) {
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> goodsList = goodsDao.getList(goodsVo);
        return new PageInfo<>(goodsList);
    }

    @Override
    public List<Goods> getListById(Integer id) {
        return goodsDao.getListById(id);
    }

    @Override
    public boolean saveOrUpdate(Goods goods) {
        boolean a;
        if(goods.getId()==null){
            a=goodsDao.save(goods);
        }else{
            a=goodsDao.up(goods);
        }
        System.out.println("a:"+a);
        return a;
    }

    @Override
    public Goods getUpById(Integer id) {
        return goodsDao.getUpById(id);
    }

    @Override
    public boolean delete(Integer id) {
        return goodsDao.delete(id);
    }
}
